#ifndef DBADAPTER_H
#define DBADAPTER_H
#include "dbhelper.h"
#include "QList"
#include "QVariantMap"
#include "dateinteger.h"
#include "bizqueryhelper.h"
#include "toolhelper.h"
#include "QString"

#include <QObject>

class DBAdapter : public QObject
{
    Q_OBJECT
public:
    explicit DBAdapter(QObject *parent = 0);
    explicit DBAdapter(QString dbName,QObject *parent = 0);
    QString _db;
signals:

public slots:
    //基础
    //true:不需要初始化，或者初始化成功 false:脚本执行有误
    bool InitDb();

    int Insert(QString table,QVariantMap map);
    bool Update(QString table,int fid,QVariantMap map);
    QList<QVariantMap> Select(QString table,QVariantMap map,QStringList columns,QString filter);
    bool Delete(QString table,QString filter);

    //获取用户余额
    qreal GetUserAsset();

    //列表查询
    QList<QVariantMap> GetAllPayment(QDate fromDate,QDate toDate,int UserId);
    QList<QVariantMap> GetAllIncome(QDate fromDate,QDate toDate,int UserId);
    QList<QVariantMap> GetPaymentType();
    QList<QVariantMap> GetIncomeType();

    //报表
    //收入类型统计报表
    QList<QVariantMap> GetIncomeRptGroupByType(QDate fromDate,QDate toDate,int UserId);
    //支出类型统计报表
    QList<QVariantMap> GetPaymentRptGroupByType(QDate fromDate,QDate toDate,int UserId);
    //时间段收入/支出报表
    QList<QVariantMap> GetIncomeRpt(QDate fromDate,QDate toDate,int UserId,QString filter = "");
    QList<QVariantMap> GetPaymentRpt(QDate fromDate,QDate toDate,int UserId,QString filter = "");
    QList<QVariantMap> GetdayPaymentRpt(QDate d,int UserId,QString filter = "");
    
    int GetPaymentCount();
    int GetIncomeCount();
    qreal GetPaymentSum();
    qreal GetIncomeSum();
    QDateTime GetLastDate();
};

#endif // DBADAPTER_H
